
var myphoneno = '+17327101856';
function getObj(id) {
  return document.getElementById(id);
}

function getPhNo()
{
	//alert('inside getPhNo');
	return myphoneno;
}

function setText(o, id)
{
	//var id = "id_ph_no";
	var actValue = "";
	//alert('inside setPhNo');
	//alert(id);
      var actDivObj = getObj(id);
  	if(actDivObj != null) {
    		actValue = actDivObj.value;
    		//alert('inside='+actValue);
  	}

	//alert(actValue);
	myphoneno = actValue;
}

function switchData(msg, contactinfo){

 if (contactinfo==null || trim(contactinfo).length==0) {
   contactinfo = "+393488513560";
 }
 var msgbase = "Trave deal from Yogi's Mashup...";

 if (msg!=null && trim(msg).length>0) {
   msgbase = msgbase + msg;
   //alert(msg);
 }

 var licenseUser = "yugans@hotmail.com";
 var licensePswd = "awansikri";
 var licenseEmail = "yugan1@prinove.com";

 alert('Sending Travel Deal Message');
 var smshref = "http://ws.strikeiron.com/StrikeIron/globalsmspro2_5/SMSTextMessaging/SendMessage?LicenseInfo.RegisteredUser.UserId="+licenseUser+"&LicenseInfo.RegisteredUser.Password="+licensePswd+"&SendMessage.ToNumber="+contactinfo+"&SendMessage.FromName=SDPSecuredTravelApp&SendMessage.MessageText="+msgbase;
 //var smshref = "http://ws.strikeiron.com/StrikeIron/globalsmspro2_5/SMSTextMessaging/SendMessage?LicenseInfo.UnregisteredUser.EmailAddress="+licenseEmail+"&SendMessage.ToNumber="+contactinfo+"&SendMessage.FromName=SDPSecuredTravelApp&SendMessage.MessageText="+msgbase;
 //var smshref = 'http://ws.strikeiron.com/StrikeIron/globalsmspro2_5/SMSTextMessaging/SendMessage?LicenseInfo.UnregisteredUser.EmailAddress=avianu@yahoo.com&SendMessage.ToNumber=+17327101856&SendMessage.FromName=IronYogi&SendMessage.MessageText=%94Ding%20ridk%20dhak%20rhak%85%20strikeitgold%94';
 window.open(smshref, 'sms', null);
 alert(smshref);

}


// function telcoSvc(svcType, msg, contactinfo, id_info){

/** TravelDeals sends details of the SelectList used for Message, and the Contacts to which SMS needs to be sent **/
function telcoSvc(svcType, msg_sponsor, id_msg_prefix, msg_body, id_sent_by, id_info){

	var msgbase = "send sms..";
	//alert('telcoSvc');
	var mapId = google.mashups.getObjectById('maptraveldeals');
	var entry = mapId.getSelectedEntry();
	//alert('entry: moment of truth');
	//alert(entry);
	var entrytitle = entry.title;
	var entrytitlevalue = entry.title.$t;
	//alert(entrytitle);
	//alert(entrytitlevalue);

	var sentByObj = getObj(id_sent_by);
	var sentByValue = sentByObj.value;

	var msgPrefixObj = getObj(id_msg_prefix);

	 var msg = msg_sponsor+ ": From " + sentByValue + ". " + msgPrefixObj.value + " --> " + entrytitlevalue;
 	 //alert(msg);


	 // id_info contains the id of the element that has the data to be processed
 	if(svcType == "gsms") {
   	//alert('outside gsms');
   	handleGroupSms(msg, sentByValue , id_info);
 }
  
  //alert('EXISTING telco service mashup');
}

/** Meetup sends details of the Feed used for Message, and the Contacts to which SMS needs to be sent **/
function telcoSvcMeetup(svcType, msg_sponsor, id_msg_prefix, msg_body, id_list_recepients, id_list_places)
{

	var msgbase = "sms..";
	//alert('telcoSvcMeetup');
      var feedPlaces = google.mashups.getObjectById(id_list_places).getData();
	//alert(feedPlaces.size());
      var feedContacts = google.mashups.getObjectById(id_list_recepients).getData();
	//alert(feedContacts.size());

	var msgPrefixObj = getObj(id_msg_prefix);
      var msg = msgPrefixObj.value + ": ";

	for(var index=0; index<feedPlaces.size(); index++) {
		var currEntry = feedPlaces.entryAt(index);
		// alert(currEntry);
		// alert(currEntry.title.$t);
		msg = msg + currEntry.title.$t + ". " + "\n";
	}

	for(var index=0; index<feedContacts.size(); index++) {
		var currEntry = feedContacts.entryAt(index);
		// alert(currEntry);
		alert(currEntry.author.name.$t);
		var currno = currEntry.author.name.$t;
      	sendSms(currno,msg, index+1, feedContacts.size());
	}

 	 //alert(msg);
}


function handleGroupSms(msg, contactinfo, id_info) {
	//alert('handlegroupsms');
	var groupValueObj = getObj(id_info);
	//alert(groupValueObj);
	//alert(groupValueObj.length);

	for(var i=0; i<groupValueObj.length; i++) {
         var currval = groupValueObj.options[i];
	   //alert(currval);
	   var currno = currval.value;
	   //alert(currno + " " + msg);
	   sendSms(currno,msg, i+1, length);
	}

	// for each value.. send sms...
}


function sendSms(phno, msg, index, totalno) {
 var licenseUser = "yugans@hotmail.com";
 var licensePswd = "awansikri";
 var licenseEmail = "yugans@prinove.com";

 //alert(phno + "" + msg);
 alert("Sending SMS " + index + " of " + totalno + " to " + phno);
 var smshref = "http://ws.strikeiron.com/StrikeIron/globalsmspro2_5/SMSTextMessaging/SendMessage?LicenseInfo.RegisteredUser.UserId="+licenseUser+"&LicenseInfo.RegisteredUser.Password="+licensePswd+"&SendMessage.ToNumber="+phno+"&SendMessage.FromName=SDPSecuredTravelApp&SendMessage.MessageText="+msg;
 //var smshref = "http://ws.strikeiron.com/StrikeIron/globalsmspro2_5/SMSTextMessaging/SendMessage?LicenseInfo.UnregisteredUser.EmailAddress="+licenseEmail+"&SendMessage.ToNumber="+phno+"&SendMessage.FromName=SDPSecuredTravelApp&SendMessage.MessageText="+msg;
 window.open(smshref, 'sms', null);
 //alert(smshref);

}

function confCallInvoke(id_contacts) {
 //alert(phno + "" + msg);
 alert("Sending confcall");
 //var smshref = "http://131.124.96.222:8001/sdpservice/ConfrenceService?userid=entia&phone1=18602585055&phone2=17327101856&tokenid=88888&time=7474744764";
  var confref = "http://131.124.96.222:8001/sdpservice/ConfrenceService?userid=entia&tokenid=88888&time=7474744764";

      var feedContacts = google.mashups.getObjectById(id_contacts).getData();
	//alert(feedContacts.size());

	for(var index=0; index<feedContacts.size(); index++) {
		var currEntry = feedContacts.entryAt(index);
		var phidx = index+1;
		// alert(currEntry);
		// alert(currEntry.author.name.$t);
		var currno = currEntry.author.name.$t;
		confref = confref + "&phone"+phidx+"="+currno;
      	//sendSms(currno,msg, index+1, feedContacts.size());
	}
	alert(confref);
 	window.open(confref, 'sms', null);
 	//alert(smshref);
}


function addGroupContact(o,id_group_list,id_group_ph_no) {
	var groupValueObj = getObj(id_group_list);
	var textValueObj = getObj(id_group_ph_no);
	//alert('addGroupContact');
	groupValueObj.options[groupValueObj.length] = new Option(textValueObj.value,textValueObj.value);
}


function deleteGroupContact(o,id_group_list,id_group_ph_no) {
  //alert('deleteGroupContact');
  var elSel = getObj(id_group_list);
  var i;
  for (i = elSel.length - 1; i>=0; i--) {
    if (elSel.options[i].selected) {
      elSel.remove(i);
    }
  }
}